#include "JoyPosCtrl.h"


BEGIN_EVENT_TABLE(wxJoyPosCtrl, wxScrolledWindow)
  EVT_SIZE    (wxJoyPosCtrl::OnSize)
END_EVENT_TABLE()


wxJoyPosCtrl::wxJoyPosCtrl(wxWindow *parent, const wxPoint& pos, const wxSize& size)
: wxScrolledWindow(parent,wxID_ANY,pos,size)
{
	this->SetBackgroundColour(*wxWHITE);
}

wxJoyPosCtrl::~wxJoyPosCtrl(void)
{
}

void wxJoyPosCtrl::OnDraw(wxDC& dc)
{
	dc.SetPen(*wxBLACK_PEN);
	dc.DrawLine(m_CtrlPoint.x - 2, m_CtrlPoint.y, m_CtrlPoint.x + 3, m_CtrlPoint.y);
	dc.DrawLine(m_CtrlPoint.x, m_CtrlPoint.y - 2, m_CtrlPoint.x, m_CtrlPoint.y + 3);
	//dc.DrawPoint(m_CtrlPoint);
}

void wxJoyPosCtrl::SetJoyPosition(wxPoint &point)
{
	if(m_JoyPoint!=point)
	{		
		m_JoyPoint = point;
		m_CtrlPoint = Prescale(point);
		Refresh();
		//wxLogDebug(_("Status: [%d,%d]"),m_CtrlPoint.x,m_CtrlPoint.y);;
	}
}

wxPoint wxJoyPosCtrl::Prescale(wxPoint &point)
{
		wxSize ctrlSize = this->GetSize();
		wxPoint scaled;

		unsigned short x,y;
		x = (unsigned short)point.x;
		y = (unsigned short)point.y;

		scaled.x = (int) (((float)x/0xffff) *(ctrlSize.x - 1)); 
		scaled.y = (int) (((float)y/0xffff) *(ctrlSize.y - 1)); 

		return scaled;
}

void wxJoyPosCtrl::OnSize(wxSizeEvent& event)
{
		m_CtrlPoint = Prescale(m_JoyPoint);
}



